package com.city.service.house.impl;
/*
 * @Author: 李顺时
 * @Description:
 * @Date: Create in 12:37 2018/7/13
 * @Modified By:
 * */

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.city.domain.house.House;
import com.city.repository.house.HouseRepository;

import com.city.service.house.HouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class HouseServiceImpl implements HouseService {

    //操作数据库的对象
    @Autowired
    private HouseRepository houseRepository;


    /*
     * @Author: 李顺时
     * @Description:
     * @Date: 11:33 2018/7/14
     */

    @Override
    public String houseGet(){

        House house1 = new House("001",1000,001,002,003,004,005,"别墅",3,5,"朝南",200,"2018年装修","空调、wifi、十室九厅","正常",20000,123.2,155.2,"2018-07-12",123);
        house1.setId(1);
        House house2 = new House("002",1000,001,002,003,004,005,"别墅",3,5,"朝南",200,"2018年装修","空调、wifi、十室九厅","正常",20000,123.2,155.2,"2018-07-12",123);
        house2.setId(2);
        List<House> list=new ArrayList<House>();
        list.add(house1);
        list.add(house2);
        Object houseList = JSON.toJSON(list);
        int count= 1;
        JSONArray ja = (JSONArray)houseList;
        String json = ja.toString();
        StringBuffer sb = new StringBuffer();
        sb.append("{\"count\":");
        sb.append(count);
        sb.append(",\"code\":");
        sb.append(0);
        sb.append(",\"msg\":");
        sb.append("null");
        sb.append(",\"data\":");
        sb.append(json);
        sb.append("}");
        String jsonString = sb.toString();

        return jsonString;
    }

}
